var t = getApp();

Component({
    data: {
        weekList: [ "一", "二", "三", "四", "五", "六", "日" ],
        monthDayList: [],
        currentYear: "",
        currentMonth: "",
        currentDay: "",
        today: "",
        selectedDate: "",
        signedList: [],
        isDisabledNextMonth: !0,
        sign_status: "",
        todayStyle: "is-today",
        nowTime: new Date().getTime()
    },
    observers: {
        currentMonth: function() {
            var t = new Date(), a = t.getFullYear(), e = t.getMonth() + 1;
            this.data.currentYear > a || this.data.currentYear == a && this.data.currentMonth >= e ? this.setData({
                isDisabledNextMonth: !0
            }) : this.setData({
                isDisabledNextMonth: !1
            });
        }
    },
    lifetimes: {
        created: function() {
            this.getSign();
        },
        ready: function() {
            this.initCurrentDate(), this.getSign();
        },
        moved: function() {},
        detached: function() {}
    },
    methods: {
        formatIosDate: function(t) {
            return t.replace(/\-/g, "/");
        },
        formatTime: function(t) {
            return [ t.getFullYear(), t.getMonth() + 1, t.getDate() ].join("/");
        },
        formatZero: function(t) {
            return t;
        },
        initCurrentDate: function(t) {
            var a = this, e = t || new Date(), n = e.getFullYear(), r = e.getMonth() + 1, c = e.getDate();
            if (!t) {
                var i = "".concat(n, "/").concat(r, "/").concat(c);
                this.setData({
                    today: i
                });
            }
            this.setData({
                currentYear: n,
                currentMonth: r,
                currentDay: c
            }, function() {
                a.initMonthDayList();
            });
        },
        initMonthDayList: function() {
            var t = new Date(this.data.currentYear, this.data.currentMonth - 1, 1).getDay(), a = new Date(this.data.currentYear, this.data.currentMonth, 0).getDate(), e = [];
            if (0 == t) for (var n = 0; n < 6; n++) e.push(null); else for (var r = 0; r < t - 1; r++) e.push(null);
            for (var c = 1; c <= a; c++) if (this.data.currentMonth >= 1 && this.data.currentMonth < 10) if (c >= 1 && c < 10) {
                var i = {
                    day: c,
                    date: "".concat(this.data.currentYear, "/0").concat(this.data.currentMonth, "/0").concat(c),
                    time: new Date("".concat(this.data.currentYear, "/").concat(this.data.currentMonth, "/").concat(c)).getTime()
                };
                e.push(i);
            } else {
                var o = {
                    day: c,
                    date: "".concat(this.data.currentYear, "/0").concat(this.data.currentMonth, "/").concat(c),
                    time: new Date("".concat(this.data.currentYear, "/").concat(this.data.currentMonth, "/").concat(c)).getTime()
                };
                e.push(o);
            } else if (this.data.currentMonth >= 10) {
                if (c >= 1 && c < 10) {
                    var s = {
                        day: c,
                        date: "".concat(this.data.currentYear, "/").concat(this.data.currentMonth, "/0").concat(c),
                        time: new Date("".concat(this.data.currentYear, "/").concat(this.data.currentMonth, "/").concat(c)).getTime()
                    };
                    e.push(s);
                } else {
                    var h = {
                        day: c,
                        date: "".concat(this.data.currentYear, "/").concat(this.data.currentMonth, "/").concat(c),
                        time: new Date("".concat(this.data.currentYear, "/").concat(this.data.currentMonth, "/").concat(c)).getTime()
                    };
                    e.push(h);
                }
                if (this.currentMonth >= 1 && this.currentMonth < 10) if (c >= 1 && c < 10) {
                    var u = {
                        day: c,
                        date: "".concat(this.currentYear, "/0").concat(this.currentMonth, "/0").concat(c),
                        time: new Date("".concat(this.currentYear, "/").concat(this.currentMonth, "/").concat(c)).getTime()
                    };
                    e.push(u);
                } else {
                    var d = {
                        day: c,
                        date: "".concat(this.currentYear, "/0").concat(this.currentMonth, "/").concat(c),
                        time: new Date("".concat(this.currentYear, "/").concat(this.currentMonth, "/").concat(c)).getTime()
                    };
                    e.push(d);
                } else if (this.currentMonth >= 10) if (c >= 1 && c < 10) {
                    var g = {
                        day: c,
                        date: "".concat(this.currentYear, "/").concat(this.currentMonth, "/0").concat(c),
                        time: new Date("".concat(this.currentYear, "/").concat(this.currentMonth, "/").concat(c)).getTime()
                    };
                    e.push(g);
                } else {
                    var l = {
                        day: c,
                        date: "".concat(this.currentYear, "/").concat(this.currentMonth, "/").concat(c),
                        time: new Date("".concat(this.currentYear, "/").concat(this.currentMonth, "/").concat(c)).getTime()
                    };
                    e.push(l);
                }
            }
            this.setData({
                monthDayList: e
            });
        },
        handleSelectDate: function(t) {
            var a = t.currentTarget.dataset.item;
            a && this.setData({
                selectedDate: a.date
            });
        },
        handlePreMonth: function() {
            this.handleToggleMonth(-1), this.getnewDate();
        },
        handleNextMonth: function() {
            this.data.isDisabledNextMonth || (this.handleToggleMonth(1), this.getnewDate());
        },
        handleToggleMonth: function(t) {
            var a = this, e = this.data.currentMonth += t, n = this.data.currentYear;
            e <= 0 ? (e = 12, n--) : e > 12 && (e = 1, n++), this.setData({
                currentYear: n,
                currentMonth: e
            }, function() {
                a.initMonthDayList(), a.triggerEvent("change", {
                    date: "".concat(n, "/").concat(e)
                });
            });
        },
        getnewDate: function() {
            var a = this, e = t.getNetAddresss("plugin.sign.Frontend.Modules.Sign.Controllers.sign-log.index");
            t._getNetWork({
                data: {
                    month: this.data.currentMonth,
                    year: this.data.currentYear
                },
                url: e,
                success: function(t) {
                    1 == t.data.result && a.setData({
                        signedList: t.data.data.sign_log
                    });
                }
            });
        },
        getSign: function() {
            var a = this, e = t.getNetAddresss("plugin.sign.Frontend.Modules.Sign.Controllers.sign-log.index");
            t._getNetWork({
                url: e,
                success: function(t) {
                    1 == t.data.result ? (wx.hideLoading(), wx.setStorage({
                        key: "sign_log",
                        data: t.data.data.sign_log
                    }), a.setData({
                        sign_status: t.data.data.sign_status,
                        signedList: t.data.data.sign_log
                    }), wx.setStorage({
                        key: "cumulative",
                        data: t.data.data.cumulative
                    })) : wx.showToast({
                        title: t.data.msg,
                        icon: "none"
                    });
                }
            });
        }
    }
});